// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  var type=event.type;
  var acfee=event.acfee;
  var efees=event.efees;
  var sushe=event.sushe;
  var money=event.money;
  //修改宿舍电费空调费余额
  if (type ==1) {
    try{
      return await db.collection('dormitory').where({
      hostel: sushe
    }).update({

      data: {
        efees: money + acfee
      }
        })
    }catch(e){
      console.err(e)
    }
    }
   else if (type ==0) {
    try {
      return await db.collection('dormitory').where({
      hostel: sushe
      
    }).update({
      
      data: {
        acfee: money + acfee
      }
     
      })
  }catch (e) {
    console.err(e)
  }
  }
}